package com.example.mrzhou.lvmm.view.adapter.tm;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.utils.ImageLoader;
import com.example.mrzhou.lvmm.entity.tm.TM;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Mr.zhou on 2016/10/29.
 */

public class TMAdapter extends RecyclerView.Adapter<TMAdapter.TMViewHolder> {

    private List<TM.DataBean.GroupbuyListBean> data;
    private Context context;

    public TMAdapter(List<TM.DataBean.GroupbuyListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public TMViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TMViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list_tm_sample, parent, false));
    }

    @Override
    public void onBindViewHolder(TMViewHolder holder, int position) {
        ImageLoader.getInstance().displayImage(data.get(position).getLargeImage(),context,holder.ivTmImg,R.drawable.hot_loading,R.drawable.hot_loading);
        holder.tvTmDiscount.setText(data.get(position).getDiscountV200()+"折");
        holder.tvTmName.setText(data.get(position).getProductName());
        holder.tvTmType.setText(data.get(position).getProductTypeV2()+" | "+data.get(position).getDeparturePlace()+"出发");
        holder.tvTmPrice.setText("¥"+data.get(position).getSellPrice()/100+"起");
        holder.tvTmStockcount.setText("仅余"+data.get(position).getStockCount()+"份");
        holder.tvTmReconname.setText(data.get(position).getRecommandName());
    }

    @Override
    public int getItemCount() {
        return data!=null?data.size():0;
    }

    public class TMViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_tm_img)
        ImageView ivTmImg;
        @BindView(R.id.tv_tm_discount)
        TextView tvTmDiscount;
        @BindView(R.id.tv_tm_name)
        TextView tvTmName;
        @BindView(R.id.tv_tm_type)
        TextView tvTmType;
        @BindView(R.id.tv_tm_price)
        TextView tvTmPrice;
        @BindView(R.id.tv_tm_stockcount)
        TextView tvTmStockcount;
        @BindView(R.id.tv_tm_reconname)
        TextView tvTmReconname;

        public TMViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
